ci: Create new origin for forks
authorEmmanuele Bassi <ebassi@gnome.org>
Sun, 28 Jun 2020 13:01:19 +0000 (14:01 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 29 Jun 2020 12:14:40 +0000 (13:14 +0100)
We don't need to create a new remote and fetch its master if we're
checking a merge request done on the upstream repository.

.gitlab-ci/run-style-check-diff.sh

index 35a1bb4a39eb817aa72666be3c410d230ac17f3d..42ef5d9feeffd766770442212d331cb376c28a20 100755 (executable)
@@ -4,8 +4,15 @@ set -e
 
 # We need to add a new remote for the upstream master, since this script could
 # be running in a personal fork of the repository which has out of date branches.
-git remote add upstream https://gitlab.gnome.org/GNOME/gtk.git
-git fetch upstream
+if [ "${CI_PROJECT_NAMESPACE}" != "GNOME" ]; then
+    echo "Retrieving the current upstream repository from ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}..."
+    git remote add upstream https://gitlab.gnome.org/GNOME/gtk.git
+    git fetch upstream
+    ORIGIN="upstream"
+else
+    echo "Reusing the existing repository on ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}"
+    ORIGIN="origin"
+fi
 
 # Work out the newest common ancestor between the detached HEAD that this CI job
 # has checked out, and the upstream target branch (which will typically be
@@ -13,7 +20,7 @@ git fetch upstream
 #
 # `${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}` is only defined if we’re running in
 # a merge request pipeline; fall back to `${CI_DEFAULT_BRANCH}` otherwise.
-newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "upstream/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent HEAD) | head -1)
+newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${ORIGIN}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent HEAD) | head -1)
 git diff -U0 --no-color "${newest_common_ancestor_sha}" | .gitlab-ci/clang-format-diff.py -binary "clang-format" -p1
 exit_status=$?